<script language="javascript">
$(function() {
	$( "#txtSubStartDate" ).datepicker({
		changeMonth: true,
		changeYear: true,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd/mm/yy"
	});
});

var ajax1=new sack();

//CHECKING UNIQUE DRIVER ID FOR ADMIN

function checkUser(tableName,condStr,val,id)
{
	qry = "select * from "+tableName+" where "+condStr+" = '"+val+"'";
		
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
	//document.write(ajax1.requestFile);
	ajax1.onCompletion = function(){resultDevice(id)};
	ajax1.runAJAX();
}

function resultDevice(id)
{
  if(ajax1.response ==1 )
  {
  	alert("Date already Exist");
  	document.getElementById(id).value = '';
	document.getElementById(id).focus();
  }
	
}
function getDeviceDetails(routeId,spanId)
{
	//document.frmRegStudent.rdAlertBy.selectedIndex = 0;	
	ajax1.requestFile = 'ajax_server.php?getRouteList='+routeId;			
	//alert(ajax1.requestFile);
	ajax1.onCompletion = function(){getAlertList(spanId)};
	//document.getElementById('selContId').innerHTML = '</option value=0>Loading...</option>';
	ajax1.runAJAX();
	
}
function getEditDeviceDetails(route1,spanId1,geoid1,route2,spanId2,geoid2)
{
	ajax1.requestFile = 'ajax_server.php?getRouteList='+route1;			
	//alert(ajax1.requestFile);
	ajax1.onCompletion = function(){
		getAlertList(spanId1,geoid1)
		ajax1.requestFile = 'ajax_server.php?getRouteList='+route2;			
		ajax1.onCompletion = function(){getAlertList(spanId2,geoid2)};
		//document.getElementById('selContId').innerHTML = '</option value=0>Loading...</option>';
		ajax1.runAJAX();
	
	};
	//document.getElementById('selContId').innerHTML = '</option value=0>Loading...</option>';
	ajax1.runAJAX();
	
	
	
}
function getAlertList(spanId,type)
{
	var alrtListArr = ajax1.response.split("@");
	var source = '';
	for(k=0;k<alrtListArr.length-1;k++)
	{
		var portVal = alrtListArr[k].split("#");
		
		if(type == portVal[0])
		{
			source += '<input type="radio" name="'+spanId+'" checked="checked" id="'+spanId+'"_"'+k+'" value="'+portVal[0]+'" />'+portVal[1]+'<br/>';
		}
		else
		{
			source += '<input type="radio" name="'+spanId+'" id="'+spanId+'"_"'+k+'" value="'+portVal[0]+'" />'+portVal[1]+'<br/>';
		}
		
	}
	document.getElementById(spanId).innerHTML = source;

}

</script>
<?php
//echo "<pre>";
//print_r($_POST);
//echo "</pre>";

if(isset($_POST[txtStudId]) && $_POST[txtStudId] !='')
{
	$sql = "SELECT * FROM tb_student_info WHERE si_id =".$_POST[txtStudId];
	$rows = $db->query($sql);
	$clientRecord = $db->fetch_array($rows);
	//print_r($clientRecord);
	
	$pickData = explode("#",$clientRecord[si_pickup_id]);
	$dropData = explode("#",$clientRecord[si_drop_id]);
	?>
    	<script language="javascript">
			getEditDeviceDetails('<?php echo $pickData[0];?>','sourcePt','<?php echo $pickData[1];?>','<?php echo $dropData[0];?>','destPt','<?php echo $dropData[1];?>');
		</script>
	<?php 
}
$getGeopoint = "SELECT * FROM tb_geofence_info WHERE tgi_clientId=".$_SESSION[clientID]." ORDER BY tgi_name ASC";
$resGeopoint = $db->query($getGeopoint);
$totPoint = $db->affected_rows;

$devices_query =  "SELECT * FROM tb_deviceinfo,tb_route_info WHERE tri_deviceId  = di_id AND di_clientId =".$_SESSION[clientID]." AND di_status = 1 ORDER BY di_deviceName,di_deviceId ASC";
$devices_resp = mysql_query($devices_query);	

?>
<div align="left" class="listofusers"><a href="#" onclick="location.href='?ch=viewStudent';">List of Students</a>&nbsp;</div>
<form name="frmRegStudent" id="frmRegStudent" action="?ch=Student" method="post" autocomplete="off">
<input type="hidden" name="txtPickUp" id="txtPickUp" value="<?php echo $pickData[1];?>" />
<input type="hidden" name="txtDrop" id="txtDrop" value="<?php echo $dropData[1];?>" />
<?php
if(isset($_POST[txtStudId]) && $_POST[txtStudId] !=''){
?>
	<input type="hidden" name="txtStudId" id="txtStudId" value="<?php echo $_POST[txtStudId];?>"/>  
<?php } ?>

 	<div class="form_area"><!-- form area div start here -->
   <ul class="form">
        <li>
            <label>First Name </label>
                <input type="text" id="txtFirstName" name="txtFirstName" value="<?php echo $clientRecord[si_firstName];?>" maxlength="15"  /></td>
        </li>
        <li>
            <label>Last Name</label>
              <input type="text" id="txtLastName" name="txtLastName" value="<?php echo $clientRecord[si_lastName];?>" maxlength="10"/>
        </li>
        <li>
            <label>Standard</label>
              <input type="text"  id="txtStandard" name="txtStandard"  value="<?php echo $clientRecord[si_standard];?>"/>
        </li>
        <li>
            <label>Section </label>
            <input type="text" id="txtSection"  name="txtSection" value="<?php echo $clientRecord[si_section];?>" />
        </li>
        <li>
            <label>Roll No</label>
              <input type="text"  id="txtRollNo" name="txtRollNo"  value="<?php echo $clientRecord[si_rollNo];?>"/>
        </li>
        <li>
            <label>RFID No </label>
            <input type="text" id="txtRFIDNo"  name="txtRFIDNo" value="<?php echo $clientRecord[si_RFIDNo];?>" />
        </li>
        <li>
            <label>Father Name</label>
            <input type="text" id="txtFatherName"  name="txtFatherName" value="<?php echo $clientRecord[si_fatherName];?>" />
        </li>
        <li>
            <label>Email</label>
            <input type="text" id="txtEmailId"  name="txtEmailId" value="<?php echo $clientRecord[si_emailId];?>" />
        </li>
        <li>
            <label>Primary Mobile</label>
            <input type="text" id="txtPrimaryMobile"  name="txtPrimaryMobile" value="<?php echo $clientRecord[si_mobile1];?>" />
        </li>
        <li>
            <label>Alternate Mobile</label>
            <input type="text" id="txtAlterMobile"  name="txtAlterMobile" value="<?php echo $clientRecord[si_mobile2];?>" />
        </li>
        <li>
            <label>Select Pickup Route</label>
			<select name="txtRoutePickupId" id="txtRoutePickupId" tabindex="1" style="width:60%" onchange="getDeviceDetails(this.value,'sourcePt')">
            <option value="0">Select Route</option>
             <?php
            while($devices_fetch = @mysql_fetch_assoc($devices_resp)) 
            { 
                if($devices_fetch[di_deviceName])
                    $devName = $devices_fetch[di_deviceName]." - ".ucfirst($devices_fetch[tri_routeName]);
                else
                    $devName = $devices_fetch[di_deviceId]." - ".ucfirst($devices_fetch[tri_routeName]);
            ?>
            <option value="<?php echo $devices_fetch[tri_id]; ?>" 
            <?php if($devices_fetch[tri_id] == $pickData[0]) echo 'selected="selected"'; ?>><?php echo ucfirst($devName); ?></option>
            <?php } ?>		
            </select>
        </li>
         <li>
            <label>Select Drop Route</label>
			<select name="txtRouteDropId" id="txtRouteDropId" tabindex="1" style="width:60%" onchange="getDeviceDetails(this.value,'destPt')">
            <option value="0">Select Route</option>
             <?php
			 $devices_resp = mysql_query($devices_query);	
            while($devices_fetch = @mysql_fetch_assoc($devices_resp)) 
            { 
                if($devices_fetch[di_deviceName])
                    $devName = $devices_fetch[di_deviceName]." - ".ucfirst($devices_fetch[tri_routeName]);
                else
                    $devName = $devices_fetch[di_deviceId]." - ".ucfirst($devices_fetch[tri_routeName]);
            ?>
            <option value="<?php echo $devices_fetch[tri_id]; ?>" 
            <?php if($devices_fetch[tri_id] == $dropData[0]) echo 'selected="selected"'; ?>><?php echo ucfirst($devName); ?></option>
            <?php } ?>		
            </select>
        </li>
        <li>
            <label>Pick Point</label>
			<span id="sourcePt" style="width:60%; margin-left:5%; text-align:left; float:left; height:100px; overflow-Y:scroll">
            Select Bus to get stop List</span>
        </li>
        <li>
            <label>Drop Point</label>
			<span id="destPt" style="width:60%; text-align:left; margin-left:5%; float:left; height:100px; overflow-Y:scroll">Select Bus to get stop List</span>
        </li>
         <li>
            <label>Address</label>
            <textarea id="txtStudAddress" class="text_area" name="txtStudAddress" cols="40" rows="3"><?php echo $clientRecord[si_address];?></textarea>
        </li>
 </ul>    
         <p class="btn_area"> 
                <?php  if(isset($_POST[txtStudId]) && $_POST[txtStudId] !='')
                {
                ?>
                    <input type="submit" name="cmdSubmitUpdateStudent" id="cmdSubmitUpdateStudent" value="Update" class="save_btn" />  
              <?php } else { ?>
                    <input type="submit" name="cmdSubmitAddStudent" id="cmdSubmitAddStudent" value="Submit" class="save_btn" />
                    <input type="reset" value="Reset" class="save_btn" />
              <?php } ?>
        </p>   
</div>                   
</form>
 <script language="javaScript" type="text/javascript">

//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("frmRegStudent");
  
  frmvalidator.addValidation("txtFirstName","req","Please enter First Name");
  frmvalidator.addValidation("txtFirstName","minlen=3",	"Min length for First Name is 5");
  frmvalidator.addValidation("txtFirstName","alpha_s","First Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("txtLastName","req","Please enter Last Name");
  frmvalidator.addValidation("txtLastName","alpha_s","Last Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("txtStandard","req","Please enter Standard");
  frmvalidator.addValidation("txtStandard","alpha_s","Standard can contain alphabetic chars only");
 
  frmvalidator.addValidation("txtSection","req","Please enter Section");
   
  frmvalidator.addValidation("txtRollNo","req","Please enter Roll No");
  frmvalidator.addValidation("txtRollNo","minlen=2","Min length for Roll No is 2");
  frmvalidator.addValidation("txtRollNo","numeric","Please enter valid Roll number");
  
  frmvalidator.addValidation("txtRFIDNo","req","Please enter RFID No");
  frmvalidator.addValidation("txtRFIDNo","minlen=3");
  frmvalidator.addValidation("txtRFIDNo","numeric","Please enter valid RFID number");
  
  frmvalidator.addValidation("txtFatherName","req","Please enter Father Name");
  frmvalidator.addValidation("txtFatherName","alpha_s","Father Name can contain alphabetic chars only");

  frmvalidator.addValidation("txtEmailId","req","Please enter Email ID");
  frmvalidator.addValidation("txtEmailId","email","Please enter valid Email ID");
  
  frmvalidator.addValidation("txtPrimaryMobile","req","Please enter Primary Mobile Number");
  frmvalidator.addValidation("txtPrimaryMobile","maxlen=10");
  frmvalidator.addValidation("txtPrimaryMobile","numeric","Please enter Primary Mobile Number");
  
  /*frmvalidator.addValidation("txtAlterMobile","req","Please enter Alternate Mobile Number");
  frmvalidator.addValidation("txtAlterMobile","maxlen=10");
  frmvalidator.addValidation("txtAlterMobile","numeric","Please enter Alternate Mobile Number");*/
  
  frmvalidator.addValidation("txtRoutePickupId","dontselect=0","Please Select Pickup Route")
  frmvalidator.addValidation("txtRouteDropId","dontselect=0","Please Select Drop Route")
  frmvalidator.addValidation("txtStudAddress","maxlen=150");
 
</script>   
